"use strict";
cc._RF.push(module, '97b4cTo/t5GWZP8dO+4HhIG', 'comSpSkeleton');
// scripts/engines/components/comSpSkeleton.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var _a = cc._decorator, menu = _a.menu, ccclass = _a.ccclass;
var comSpSkeleton = /** @class */ (function (_super) {
    __extends(comSpSkeleton, _super);
    function comSpSkeleton() {
        var _this = _super.call(this) || this;
        //回调监听次数
        _this.m_completeCount = 0;
        //回调函数
        _this.m_completeCallback = null;
        //事件回调
        _this.m_trackEntryEventCallback = null;
        //事件回调监听几欠
        _this.m_trackEventCount = 0;
        //当前皮肤
        _this.m_currSkinName = null;
        return _this;
    }
    comSpSkeleton.prototype.start = function () {
        this.m_currSkinName = this.defaultSkin;
    };
    /**
     * 播放动画
     * @param animationName 动画名称
     */
    comSpSkeleton.prototype.playAnimation = function (animationName) {
        var _this = this;
        this.m_completeCount = 0;
        this.m_completeCallback = null;
        this.m_trackEventCount = 0;
        this.m_trackEntryEventCallback = null;
        //
        var then = {
            onComplete: function (callCount, callFunc) {
                _this.m_completeCount = callCount;
                _this.m_completeCallback = callFunc;
                return then;
            },
            onEvent: function (callCount, callFunc) {
                _this.m_trackEventCount = callCount;
                _this.m_trackEntryEventCallback = callFunc;
                return then;
            },
            start: function (loop) {
                //先监听回调
                _this.setCompleteListener(_this.onPlayAnimationOver.bind(_this));
                //
                var track = _this.setAnimation(0, animationName, loop);
                //事件监听
                _this.setEventListener(_this.onPlayEvent.bind(_this));
                // this.setTrackEventListener(track, this.onPlayEvent.bind(this));
                //
                return then;
            },
        };
        //
        return then;
    };
    comSpSkeleton.prototype.getCurrAnimation = function () {
        return this.getCurrent(0).animation;
    };
    //获取当前动作需要时间
    comSpSkeleton.prototype.getCurrAnimationEndTime = function () {
        if (this.getCurrAnimation()) {
            return this.getCurrAnimation().duration;
        }
    };
    //获取当前动作名称
    comSpSkeleton.prototype.getCurrAnimationName = function () {
        if (this.getCurrAnimation()) {
            return this.getCurrAnimation().name;
        }
    };
    //获取当前播放时间
    comSpSkeleton.prototype.getCurrAnimationPlayTime = function () {
        return this.getCurrent(0).trackTime;
    };
    //设置当前播放时间
    comSpSkeleton.prototype.setCurrAnimationPlayTime = function (time) {
        this.getCurrent(0).trackTime = time;
    };
    /**
     * 切换插槽附件
     * @param srcSlotName 源插槽
     * @param deskSlotName 目标插槽
     * @param srcSkeleton 源骨骼 默认为自身
     * @param srcSkin 源皮肤 默认为空 srcSkeleton与srcSkin不能同时缺省
     */
    comSpSkeleton.prototype.replaceTheSlot = function (srcSlotName, deskSlotName, srcSkeleton, srcSkin) {
        if (!srcSkeleton && !srcSkin) {
            console.error('#1171033 参数3、4不能同时为空');
            return;
        }
        var src = srcSkeleton || this;
        var meSlot = this.findSlot(deskSlotName);
        //
        var lastSrcSkin = src.getCurrSkinName();
        //
        if (srcSkin) {
            src.setSkin(srcSkin);
        }
        //
        var srcSlot = src.findSlot(srcSlotName);
        var srcAttachment = srcSlot.getAttachment();
        //
        src.setSkin(lastSrcSkin);
        meSlot.setAttachment(srcAttachment);
    };
    comSpSkeleton.prototype.setSkin = function (skinName) {
        _super.prototype.setSkin.call(this, skinName);
        this.m_currSkinName = skinName;
    };
    comSpSkeleton.prototype.getCurrSkinName = function () {
        return this.m_currSkinName;
    };
    comSpSkeleton.prototype.onPlayAnimationOver = function () {
        //有回调并且还有次数
        if (this.m_completeCallback && this.m_completeCount != 0) {
            this.m_completeCallback();
            this.m_completeCount--;
        }
        //事件回调也在播放一次时计数
        if (this.m_trackEntryEventCallback && this.m_trackEventCount != 0) {
            this.m_trackEventCount--;
        }
    };
    comSpSkeleton.prototype.onPlayEvent = function (trackEntry, event) {
        //
        if (this.m_trackEntryEventCallback && this.m_trackEventCount != 0) {
            this.m_trackEntryEventCallback(trackEntry, event);
        }
    };
    comSpSkeleton = __decorate([
        ccclass,
        menu('框架组件/骨骼动画')
    ], comSpSkeleton);
    return comSpSkeleton;
}(sp.Skeleton));
exports.default = comSpSkeleton;

cc._RF.pop();